package com.jiangyao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jiangyao.model.vo.ProvinceVo;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.util.List;

@Component
@Slf4j
public class Runner implements ApplicationRunner {

	public static List<ProvinceVo> list_province = null;
	
	@Override
	public void run(ApplicationArguments args) throws Exception {
		// 读取文件中的接送字符串并将接送解析为对象
		File file =  ResourceUtils.getFile("/var/local/address/province-city.json");
		//File file =  ResourceUtils.getFile("classpath:static/province-city.json");
		ObjectMapper mapper = new ObjectMapper();
		list_province = mapper.readValue(file,new TypeReference<List<ProvinceVo>>() {});
		log.info("获取省市区成功");
	}
}
